home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / MW MPW Binaries 1.1.1a2 / mwcPPC / MWCIncludes / complex < prev    next >
Encoding:
Text File  |  1994-07-18  |  8.3 KB  |  289 lines  |  [TEXT/MMCC]

  1. // complex standard header
  2. #ifndef _COMPLEX_
  3. #define _COMPLEX_
  4. #include <istream>
  5. #include <ostream>
  6. #define __STD_COMPLEX
  7.  
  8. #if __MWERKS__
  9. #pragma options align=mac68k
  10. #endif
  11.  
  12.         // class float_complex
  13. class float_complex {
  14. public:
  15.     float_complex(float _R = 0, float _I = 0)
  16.         : _Re(_R), _Im(_I) {}
  17.     float_complex operator+=(float_complex _R)
  18.         {_Re += _R._Real(), _Im += _R._Imag();
  19.         return (*this); }
  20.     float_complex operator-=(float_complex _R)
  21.         {_Re -= _R._Real(), _Im -= _R._Imag();
  22.         return (*this); }
  23.     float_complex operator*=(float_complex);
  24.     float_complex operator/=(float_complex);
  25.     float _Real() const
  26.         {return (_Re); }
  27.     float _Imag() const
  28.         {return (_Im); }
  29. private:
  30.     float _Re, _Im;
  31.     };
  32.         // class double_complex
  33. class double_complex {
  34. public:
  35.     double_complex(double _R = 0, double _I = 0)
  36.         : _Re(_R), _Im(_I) {}
  37.     double_complex operator+=(double_complex _R)
  38.         {_Re += _R._Real(), _Im += _R._Imag();
  39.         return (*this); }
  40.     double_complex operator-=(double_complex _R)
  41.         {_Re -= _R._Real(), _Im -= _R._Imag();
  42.         return (*this); }
  43.     double_complex operator*=(double_complex);
  44.     double_complex operator/=(double_complex);
  45.     double _Real() const
  46.         {return (_Re); }
  47.     double _Imag() const
  48.         {return (_Im); }
  49. private:
  50.     double _Re, _Im;
  51.     };
  52.         // class long_double_complex
  53. class long_double_complex {
  54. public:
  55.     long_double_complex(long double _R = 0, long double _I = 0)
  56.         : _Re(_R), _Im(_I) {}
  57.     long_double_complex operator+=(long_double_complex _R)
  58.         {_Re += _R._Real(), _Im += _R._Imag();
  59.         return (*this); }
  60.     long_double_complex operator-=(long_double_complex _R)
  61.         {_Re -= _R._Real(), _Im -= _R._Imag();
  62.         return (*this); }
  63.     long_double_complex operator*=(long_double_complex);
  64.     long_double_complex operator/=(long_double_complex);
  65.     long double _Real() const
  66.         {return (_Re); }
  67.     long double _Imag() const
  68.         {return (_Im); }
  69. private:
  70.     long double _Re, _Im;
  71.     };
  72.         // type definitions
  73. typedef float_complex _FC;
  74. typedef double_complex _DC;
  75. typedef long_double_complex _LDC;
  76.         // float_complex functions
  77. inline float imag(_FC _X)
  78.     {return (_X._Imag()); }
  79. inline float real(_FC _X)
  80.     {return (_X._Real()); }
  81. inline _FC _float_complex(const _DC& _X)
  82.     {return (_FC((float)_X._Real(), (float)_X._Imag())); }
  83. inline _FC _float_complex(const _LDC& _X)
  84.     {return (_FC((float)_X._Real(), (float)_X._Imag())); }
  85. inline _FC operator+(_FC _L, _FC _R)
  86.     {return (_L += _R); }
  87. inline _FC operator+(_FC _L, float _R)
  88.     {return (_L += _R); }
  89. inline _FC operator+(float _L, _FC _R)
  90.     {return (_FC(_L) += _R); }
  91. inline _FC operator-(_FC _L, _FC _R)
  92.     {return (_L -= _R); }
  93. inline _FC operator-(_FC _L, float _R)
  94.     {return (_L -= _R); }
  95. inline _FC operator-(float _L, _FC _R)
  96.     {return (_FC(_L) -= _R); }
  97. inline _FC operator*(_FC _L, _FC _R)
  98.     {return (_L *= _R); }
  99. inline _FC operator*(_FC _L, float _R)
  100.     {return (_L *= _R); }
  101. inline _FC operator*(float _L, _FC _R)
  102.     {return (_FC(_L) *= _R); }
  103. inline _FC operator/(_FC _L, _FC _R)
  104.     {return (_L /= _R); }
  105. inline _FC operator/(_FC _L, float _R)
  106.     {return (_L /= _R); }
  107. inline _FC operator/(float _L, _FC _R)
  108.     {return (_FC(_L) /= _R); }
  109. inline _FC operator+(_FC _L)
  110.     {return (_L); }
  111. inline _FC operator-(_FC _L)
  112.     {return (_FC(-real(_L), -imag(_L))); }
  113. inline _Bool operator==(_FC _L, _FC _R)
  114.     {return (real(_L) == real(_R) && imag(_L) == imag(_R)); }
  115. inline _Bool operator==(_FC _L, float _R)
  116.     {return (real(_L) == _R && imag(_L) == 0); }
  117. inline _Bool operator==(float _L, _FC _R)
  118.     {return (_L == real(_R) && 0 == imag(_R)); }
  119. inline _Bool operator!=(_FC _L, _FC _R)
  120.     {return (!(_L == _R)); }
  121. inline _Bool operator!=(_FC _L, float _R)
  122.     {return (!(_L == _R)); }
  123. inline _Bool operator!=(float _L, _FC _R)
  124.     {return (!(_L == _R)); }
  125. istream& operator>>(istream&, _FC&);
  126. ostream& operator<<(ostream&, _FC);
  127. float abs(_FC);
  128. float arg(_FC);
  129. inline _FC conj(_FC _X)
  130.     {return (_FC(real(_X), -imag(_X))); }
  131. _FC cos(_FC);
  132. _FC cosh(_FC);
  133. _FC exp(_FC);
  134. _FC log(_FC);
  135. inline float norm(_FC _X)
  136.     {return (real(_X) * real(_X) + imag(_X) * imag(_X)); }
  137. _FC polar(float, float);
  138. _FC pow(_FC, _FC);
  139. _FC pow(_FC, float);
  140. _FC pow(_FC, int);
  141. _FC pow(float, _FC);
  142. _FC sin(_FC);
  143. _FC sinh(_FC);
  144. _FC sqrt(_FC);
  145.         // double_complex functions
  146. inline double imag(_DC _X)
  147.     {return (_X._Imag()); }
  148. inline double real(_DC _X)
  149.     {return (_X._Real()); }
  150. inline _DC _double_complex(const _LDC& _X)
  151.     {return (_DC((double)_X._Real(), (double)_X._Imag())); }
  152. inline _DC operator+(_DC _L, _DC _R)
  153.     {return (_L += _R); }
  154. inline _DC operator+(_DC _L, double _R)
  155.     {return (_L += _R); }
  156. inline _DC operator+(double _L, _DC _R)
  157.     {return (_DC(_L) += _R); }
  158. inline _DC operator-(_DC _L, _DC _R)
  159.     {return (_L -= _R); }
  160. inline _DC operator-(_DC _L, double _R)
  161.     {return (_L -= _R); }
  162. inline _DC operator-(double _L, _DC _R)
  163.     {return (_DC(_L) -= _R); }
  164. inline _DC operator*(_DC _L, _DC _R)
  165.     {return (_L *= _R); }
  166. inline _DC operator*(_DC _L, double _R)
  167.     {return (_L *= _R); }
  168. inline _DC operator*(double _L, _DC _R)
  169.     {return (_DC(_L) *= _R); }
  170. inline _DC operator/(_DC _L, _DC _R)
  171.     {return (_L /= _R); }
  172. inline _DC operator/(_DC _L, double _R)
  173.     {return (_L /= _R); }
  174. inline _DC operator/(double _L, _DC _R)
  175.     {return (_DC(_L) /= _R); }
  176. inline _DC operator+(_DC _L)
  177.     {return (_L); }
  178. inline _DC operator-(_DC _L)
  179.     {return (_DC(-real(_L), -imag(_L))); }
  180. inline _Bool operator==(_DC _L, _DC _R)
  181.     {return (real(_L) == real(_R) && imag(_L) == imag(_R)); }
  182. inline _Bool operator==(_DC _L, double _R)
  183.     {return (real(_L) == _R && imag(_L) == 0); }
  184. inline _Bool operator==(double _L, _DC _R)
  185.     {return (_L == real(_R) && 0 == imag(_R)); }
  186. inline _Bool operator!=(_DC _L, _DC _R)
  187.     {return (!(_L == _R)); }
  188. inline _Bool operator!=(_DC _L, double _R)
  189.     {return (!(_L == _R)); }
  190. inline _Bool operator!=(double _L, _DC _R)
  191.     {return (!(_L == _R)); }
  192. istream& operator>>(istream&, _DC&);
  193. ostream& operator<<(ostream&, _DC);
  194. double abs(_DC);
  195. double arg(_DC);
  196. inline _DC conj(_DC _X)
  197.     {return (_DC(real(_X), -imag(_X))); }
  198. _DC cos(_DC);
  199. _DC cosh(_DC);
  200. _DC exp(_DC);
  201. _DC log(_DC);
  202. inline double norm(_DC _X)
  203.     {return (real(_X) * real(_X) + imag(_X) * imag(_X)); }
  204. _DC polar(double, double);
  205. _DC pow(_DC, _DC);
  206. _DC pow(_DC, double);
  207. _DC pow(_DC, int);
  208. _DC pow(double, _DC);
  209. _DC sin(_DC);
  210. _DC sinh(_DC);
  211. _DC sqrt(_DC);
  212.         // long_double_complex functions
  213. inline long double imag(_LDC _X)
  214.     {return (_X._Imag()); }
  215. inline long double real(_LDC _X)
  216.     {return (_X._Real()); }
  217. inline _LDC operator+(_LDC _L, _LDC _R)
  218.     {return (_L += _R); }
  219. inline _LDC operator+(_LDC _L, long double _R)
  220.     {return (_L += _R); }
  221. inline _LDC operator+(long double _L, _LDC _R)
  222.     {return (_LDC(_L) += _R); }
  223. inline _LDC operator-(_LDC _L, _LDC _R)
  224.     {return (_L -= _R); }
  225. inline _LDC operator-(_LDC _L, long double _R)
  226.     {return (_L -= _R); }
  227. inline _LDC operator-(long double _L, _LDC _R)
  228.     {return (_LDC(_L) -= _R); }
  229. inline _LDC operator*(_LDC _L, _LDC _R)
  230.     {return (_L *= _R); }
  231. inline _LDC operator*(_LDC _L, long double _R)
  232.     {return (_L *= _R); }
  233. inline _LDC operator*(long double _L, _LDC _R)
  234.     {return (_LDC(_L) *= _R); }
  235. inline _LDC operator/(_LDC _L, _LDC _R)
  236.     {return (_L /= _R); }
  237. inline _LDC operator/(_LDC _L, long double _R)
  238.     {return (_L /= _R); }
  239. inline _LDC operator/(long double _L, _LDC _R)
  240.     {return (_LDC(_L) /= _R); }
  241. inline _LDC operator+(_LDC _L)
  242.     {return (_L); }
  243. inline _LDC operator-(_LDC _L)
  244.     {return (_LDC(-real(_L), -imag(_L))); }
  245. inline _Bool operator==(_LDC _L, _LDC _R)
  246.     {return (real(_L) == real(_R) && imag(_L) == imag(_R)); }
  247. inline _Bool operator==(_LDC _L, long double _R)
  248.     {return (real(_L) == _R && imag(_L) == 0); }
  249. inline _Bool operator==(long double _L, _LDC _R)
  250.     {return (_L == real(_R) && 0 == imag(_R)); }
  251. inline _Bool operator!=(_LDC _L, _LDC _R)
  252.     {return (!(_L == _R)); }
  253. inline _Bool operator!=(_LDC _L, long double _R)
  254.     {return (!(_L == _R)); }
  255. inline _Bool operator!=(long double _L, _LDC _R)
  256.     {return (!(_L == _R)); }
  257. istream& operator>>(istream&, _LDC&);
  258. ostream& operator<<(ostream&, _LDC);
  259. long double abs(_LDC);
  260. long double arg(_LDC);
  261. inline _LDC conj(_LDC _X)
  262.     {return (_LDC(real(_X), -imag(_X))); }
  263. _LDC cos(_LDC);
  264. _LDC cosh(_LDC);
  265. _LDC exp(_LDC);
  266. _LDC log(_LDC);
  267. inline long double norm(_LDC _X)
  268.     {return (real(_X) * real(_X) + imag(_X) * imag(_X)); }
  269. _LDC polar(long double, long double);
  270. _LDC pow(_LDC, _LDC);
  271. _LDC pow(_LDC, long double);
  272. _LDC pow(_LDC, int);
  273. _LDC pow(long double, _LDC);
  274. _LDC sin(_LDC);
  275. _LDC sinh(_LDC);
  276. _LDC sqrt(_LDC);
  277.  
  278. #if __MWERKS__
  279. #pragma options align=reset
  280. #endif
  281.  
  282. #endif
  283.  
  284. /*
  285.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  286.  * Consult your license regarding permissions and restrictions.
  287.  */
  288.  
  289.